﻿namespace EnergyGeneratorSimVisualizer.Views
{
    using System.Linq;
    using System.Collections.Generic;
    using System.Windows.Controls;
    using System.Windows;

    /// <summary>
    /// Interaction logic for ChartDisplayArea.xaml
    /// </summary>
    public partial class ChartDisplayArea : UserControl
    {
        public ChartDisplayArea()
        {
            InitializeComponent();
        }

        public void Update(IEnumerable<ChartDescription> chartDescriptions)
        {
            this.chartArea.Children.Clear();
            this.chartArea.RowDefinitions.Clear();

            int count = chartDescriptions.Count();

            for (int i = 0; i < count; i++)
            {
                this.chartArea.RowDefinitions.Add(
                    new RowDefinition
                    { 
                        Height = new GridLength(1, GridUnitType.Star) 
                    });
            }

            int index = 0;
            foreach (var descr in chartDescriptions)
            {
                var chart = new ChartView
                {
                    Title = descr.TitleContent,
                    BindingValue = descr.ValuePath
                };

                Grid.SetRow(chart, index);

                this.chartArea.Children.Add(chart);

                index++;
            }
        }
    }
}
